package pseudoAssemblerCompiler.twopassassembler.view.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
 * User: Роман
 * Date: 23.05.12
 * Time: 19:00
 */
public class LabeledContainer {

    private Composite _composite;

    private Composite _labelComposite;

    private Composite _controlComposite;

    private Label _label;

    public Composite getComposite() {
        return _composite;
    }

    public Composite getControlComposite() {
        return _controlComposite;
    }

    public Label get_label() {
        return _label;
    }

    public LabeledContainer(Composite parent, String aLabelName) {
        _composite = new Composite(parent, SWT.NONE);
        _labelComposite = new Composite(_composite, SWT.NONE);
        _controlComposite = new Composite(_composite, SWT.NONE);

        _label = WidgetsFactory.createLabel(_labelComposite, SWT.NONE);
        _label.setText(aLabelName);
        layouts();
    }

    private void layouts() {
        FormData formData;

        formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        _composite.setLayout(new FormLayout());
        _composite.setLayoutData(formData);

        formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(25, 0);
        formData.bottom = new FormAttachment(100, 0);
        _labelComposite.setLayout(new FormLayout());
        _labelComposite.setLayoutData(formData);

        formData = new FormData();
        formData.left = new FormAttachment(_labelComposite, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        _controlComposite.setLayout(new FormLayout());
        _controlComposite.setLayoutData(formData);

        formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        _label.setLayoutData(formData);

    }

    public void setLayoutData(Object layoutData) {
        _composite.setLayoutData(layoutData);
    }

}

